<?php 
class ServicesController extends Henry_Controller_Action
{
 
    public function init()
    {
        parent::init();
    }
    private function filterdata($params)
    {
    	$data = array();
    	if (empty($params)) return;
    	foreach ($params as $key=>$item)
    	{
    		if((stristr($key,"services_")!== false) && !empty($item))
			{
				$data[$key]= $item;
			}
    	}	
    	return $data;
    }
    public function listservicesAction()
    {    
    	$serModelOb = new Default_Model_Services();
    	$paginator = Zend_Paginator::factory($serModelOb->listServices());    	
    	$paginator->setCurrentPageNumber($this->_getParam("page")); // Note: For this to work of course, your URL must be something like this: http://localhost:8888/index/index/page/1 <- meaning we are currently on page one, and pass that value into the "setCurrentPageNumber"
		$paginator->setItemCountPerPage(20);
		$paginator->setPageRange(10);
		$this->view->paginator = $paginator;
		$this->view->link = $this->view->baseUrl()."/services/";
    }
    public function indexAction()
    {    	
    	$requestOb = $this->getRequest(); 
       	$params = $requestOb->getParams();
       	$data=$this->filterdata($params);       
        if($requestOb->isPost())
        {      	
		       $serModelOb = new Default_Model_Services();
		       if($serModelOb->addServices($data))
		       {
		       		$this->view->assign('message',array('Save successful'));
		       }        		
        }	 
        $this->view->cusItem = $data;       
        $this->view->assign('currentPage',$params['page']);
    }	
	public function deleteAction()
	{
		$serModelOb = new Default_Model_Services();
		$id = $this->_getParam('id');
		if ($serModelOb->delServices($id))
		{
			$this->_redirect("services");
		}
	}
	public function updateAction()
	{
		$id = $this->_getParam('id');
        $serModelOb = new Default_Model_Services();
		$requestOb = $this->getRequest();       
		if($requestOb->isPost())
        {
        	$params = $requestOb->getParams();
       		$data=$this->filterdata($params);  
	        if($serModelOb->updateServices($id,$data))
	        {
	        		$this->view->assign('message',array('Update successful'));
	        }
        }	
        $this->view->servicesItem = $serModelOb->getServices($id);        
        $this->view->assign('currentPage',$params['page']);
	}
}

?>